#include "filesetwidget.h"
#include "ui_filesetwidget.h"

FileSetWidget::FileSetWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::FileSetWidget)
{
    ui->setupUi(this);
    setWindowFlags(Qt::FramelessWindowHint);//去掉标题栏
    //setAutoFillBackground(false);  //这个不设置的话就背景变黑
    //setAttribute(Qt::WA_TranslucentBackground,true);
    ui->exit->setFlat(true);
    ui->widget_2->setVisible(false);
    ui->widget_3->setVisible(false);
    //move(QPoint(100,100));

    setWindowFlags(Qt::FramelessWindowHint | Qt::Dialog);
    setWindowModality(Qt::WindowModal);
}

FileSetWidget::~FileSetWidget()
{
    delete ui;
}

void FileSetWidget::on_pushButton_clicked()
{
    ui->widget_2->setVisible(true);
    ui->widget_3->setVisible(false);
}

void FileSetWidget::on_pushButton_2_clicked()
{
    ui->widget_2->setVisible(false);
    ui->widget_3->setVisible(true);
}

/**
 * @brief FileSetWidget::mousePressEvent
 * @param event
 */
void FileSetWidget::mousePressEvent(QMouseEvent *event)
{
    if((event->button() == Qt::LeftButton) && QRect(0,0,400,30).contains(this->mapFromGlobal(QCursor::pos())))
    {
        QCursor cursor;
        cursor.setShape(Qt::ClosedHandCursor);
        QApplication::setOverrideCursor(cursor);
        offset = event->globalPos() - pos();
    }
}

/**
 * @brief FileSetWidget::mouseMoveEvent
 * @param event
 */
void FileSetWidget::mouseMoveEvent(QMouseEvent *event)
{
    if((event->buttons() & Qt::LeftButton) && QRect(0,0,400,30).contains(this->mapFromGlobal(QCursor::pos())))
    {
        QPoint temp;
        temp = event->globalPos() - offset;
        move(temp);
    }
}

/**
 * @brief FileSetWidget::mouseReleaseEvent
 * @param event
 */
void FileSetWidget::mouseReleaseEvent(QMouseEvent *event)
{
    QApplication::restoreOverrideCursor();
}

/**
 * @brief FileSetWidget::on_confirm_clicked
 */
void FileSetWidget::on_confirm_clicked()
{
    emit locationPath(ui->path->text());
}

void FileSetWidget::on_login_clicked()
{
    emit FTPConfirm(ui->host->text(),ui->port->text().toInt(),ui->uesrName->text(),ui->password->text(),ui->FTP_path->text());
}
